//
//  DutyParentsViewController.m
//  MobileOffice
//
//  Created by jjkj on 16/11/1.
//  Copyright © 2016年 liaoningjujin. All rights reserved.
//

#import "DutyParentsViewController.h"



@interface DutyParentsViewController ()
{


    //DatePickerView *_datePickerView;//时间选择框
}

@end

@implementation DutyParentsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //增加监听，当键盘出现或改变时收出消息
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillShow:)
                                                 name:UIKeyboardWillShowNotification
                                               object:nil];
    
    //增加监听，当键退出时收出消息
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillHide:)
                                                 name:UIKeyboardWillHideNotification
                                               object:nil];
//    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(datePickViewSure:) name:@"datePickViewSure" object:nil];
//    [[NSNotificationCenter defaultCenter]addObserver:self
//                                            selector:@selector(datePickViewCancel:)
//                                                name:@"datePickViewCancel"
//                                              object:nil];
    if (_dutyType==ApplyHoliday) {
        [self setNavigationTitle:[_navaTitle stringByAppendingString:@"申请"]];
    }else{
        [self setNavigationTitle:[_navaTitle stringByAppendingString:@"补假申请"]];
    }
    if (self.vacateBillId) {
        [self getVacateInfoRequestWithVacateBillId:self.vacateBillId];
    }
    [self setLeftBackNavigation];
    [self setRightNavigation:@""];
    [self dataInit];
    [self creatView];
    [self getCountdownTimeInfoRequest];//获取时间管控
    [self getPersonalDaysInfoRequest];//年假天数
    [self getManagementInfoRequest];//制度详细信息
    [self serverDateRequest];

    // Do any additional setup after loading the view.
}

//- (void)datePickViewSure:(NSNotification *)notification{
//    NSDictionary *dict=[notification userInfo];
//    [LZXHelper postMessageWithText:dict[@"userInfo"] View:self.view];
//}

//- (void)datePickViewCancel:(NSNotification *)notification{
    //if (_datePickerView) {
       // [_datePickerView removeFromSuperview];
       // _datePickerView=nil;
    //}
//}

#pragma mark -键盘弹出的通知事件
- (void)keyboardWillShow:(NSNotification *)aNotification
{
    NSDictionary *userInfo = [aNotification userInfo];
    NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGRect keyboardRect = [aValue CGRectValue];
    CGFloat height = keyboardRect.size.height;
    _tableView.height=IPHONE_HEIGHT-104-height;
    [self addTapGestureRecognizer];
    // CGFloat width = keyboardRect.size.width;
}

- (void)addTapGestureRecognizer{
    //避免手势混乱 所以先移除
    if (_tapGesture) {
        [_tableView removeGestureRecognizer:_tapGesture];
        _tapGesture=nil;
    }
    _tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapGestureClick)];
    [_tableView addGestureRecognizer:_tapGesture];
}

- (void)removeTapGestureRecognizer{
    [_tableView removeGestureRecognizer:_tapGesture];
    _tapGesture=nil;
}

#pragma mark -键盘退出的通知事件
- (void)keyboardWillHide:(NSNotification *)aNotification
{
    //    //获取键盘高度
    //    NSDictionary *userInfo = [aNotification userInfo];
    //    NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
    //    CGRect keyboardRect = [aValue CGRectValue];
    //    CGFloat height = keyboardRect.size.height;
    
    //    [UIView animateWithDuration:0.3 animations:^{
    //        _backMsgView.y=IPHONE_HEIGHT-51;
    //    }];
    _tableView.height=IPHONE_HEIGHT-104;
    [self removeTapGestureRecognizer];
    //_tableView.y=64;
    
}


#pragma mark -textViewDelegate

- (void)textViewDidBeginEditing:(UITextView *)textView{
    //滚动输入框 避免被键盘遮挡
    [self setLabelBorderColorWithLabel:_reasonTitleLabel color:[UIColor clearColor]];
    NSIndexPath* path = [NSIndexPath indexPathForRow:3 inSection:1];
    [self performSelector:@selector(scrollToCell:) withObject:path afterDelay:0];
}

-(void) scrollToCell:(NSIndexPath*) path {
    [_tableView scrollToRowAtIndexPath:path atScrollPosition:UITableViewScrollPositionTop animated:YES];
}

//- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
//    [_reasonList showSuggestionsFor:textView shouldChangeCharactersInRange:range replacementString:text];
////    NSIndexPath* path = [NSIndexPath indexPathForRow:3 inSection:1];
////    CGRect rectInTableView = [_tableView rectForRowAtIndexPath:path];
////    
////    
////    CGRect rect = [_tableView convertRect:rectInTableView toView:[tableView superview]];
//    _reasonList.view.frame=CGRectMake(textView.x, textView.y+textView.height, textView.width, 200);
//    [self.view addSubview:_reasonList.view];
//    
//    return YES;
//}



- (BOOL)textViewShouldEndEditing:(UITextView *)textView{
    return YES;
}



#pragma mark -手势的响应事件
- (void)tapGestureClick{
    [self.view endEditing:YES];
}


#pragma mark -初始化数据
- (void)dataInit{
    NSArray *array = [NSArray arrayWithObjects:@"a art.一(个)；每一(个)",
                      @"abandon vt.丢弃；放弃，抛弃",
                      @"ability n.能力；能耐，本领",
                      @"able a.有能力的；出色的",
                      @"abnormal a.不正常的；变态的",
                      @"aboard ad.在船(车)上；上船",
                      @"about prep.关于；在…周围",
                      @"above prep.在…上面；高于",
                      @"abroad ad.(在)国外；到处",
                      @"absence n.缺席，不在场；缺乏",
                      @"absent a.不在场的；缺乏的",
                      @"absolute a.绝对的；纯粹的",
                      @"absolutely ad.完全地；绝对地",
                      @"absorb vt.吸收；使专心",
                      @"abstract a.抽象的 n.摘要",
                      @"abundant a.丰富的；大量的",
                      @"abuse vt.滥用；虐待 n.滥用",
                      @"academic a.学院的；学术的",
                      @"academy n.私立中学；专科院校",
                      @"accelerate vt.(使)加快；促进",
                      @"acceleration n.加速；加速度",
                      @"accent n.口音，腔调；重音",
                      @"accept vt.vi.接受；同意",
                      @"acceptable a.可接受的，合意的",
                      @"acceptance n.接受，验收；承认",
                      @"access n.接近；通道，入口",
                      @"accessory n.同谋，从犯；附件",
                      @"accident n.意外的；事故",
                      @"accidental a.偶然的；非本质的",
                      @"accommodate vt.容纳；供应，供给",
                      @"accommodation n.招待设备；预定铺位",
                      @"accompany vt.陪伴，陪同；伴随",
                      @"accomplish vt.达到(目的)；完成",
                      @"accord vt.使一致；给予",
                      @"accordance n.一致；和谐；授予",
                      @"accordingly ad.因此，所以；照着",
                      @"account n.记述；解释；帐目",
                      @"accumulate vt.积累 vi.堆积",
                      @"accuracy n.准确(性)；准确度",
                      @"accurate a.准确的，正确无误的",
                      @"accuse vt.指责；归咎于",
                      @"accustom vt.使习惯",
                      @"accustomed a.惯常的；习惯的",
                      @"ache vi.痛；想念 n.疼痛",
                      @"achieve vt.完成，实现；达到",
                      @"achievement n.完成；成就，成绩",
                      @"acid n.酸；酸的，酸性的",
                      @"acquaintance n.认识；了解；熟人",
                      @"acquire vt.取得；获得；学到",
                      @"acre n.英亩(=6.07亩)",
                      @"across prep.横过；在…对面",
                      @"act vi.行动；见效 n.行为",
                      @"action n.行动；作用；功能",
                      @"active a.活跃的；积极的",
                      @"activity n.活动；活力；行动",
                      @"actor n.男演员；演剧的人",
                      @"actress n.女演员",
                      @"actual a.实际的；现行的",
                      @"actually ad.实际上；竟然",
                      @"acute a.尖的，锐的；敏锐的",
                      @"ad n.广告",
                      @"adapt vt.使适应；改编",
                      @"add vt.添加，附加，掺加",
                      @"addition n.加，加法；附加物",
                      @"additional a.附加的，追加的",
                      @"address n.地址；演说；谈吐",
                      @"adequate a.足够的；可以胜任的",
                      @"adjective n.形容词 a.形容词的",
                      @"adjust vt.调整，调节；校正",
                      @"administration n.管理；管理部门",
                      @"admire vt.钦佩，羡慕，赞赏",
                      @"admission n.允许进入；承认",
                      nil];
    _mustSelectArr=[NSMutableArray new];
    _addWorkPersonArr=[NSMutableArray new];
    _titleArr=@[@"开始时间 :",@"结束时间 :",@"调休天数 :"];
    _messageArr=[NSMutableArray arrayWithArray:@[self.beginStr?self.beginStr:@"点击选择",self.endStr?self.endStr:@"点击选择",@"0  天"]];
    self.reasonList = [[ReasonListTableViewController alloc] initWithArray:array];
    if (_beginStr&&_endStr) {
        [self getVacateDaysOnlyRequest];
    }
}

#pragma mark — creatView
- (void)creatView{
    UIView *userInfoView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, 40)];
    userInfoView.backgroundColor=COLOR_SKYBLUE;
    [self.view addSubview:userInfoView];
    
    self.vacationTime=[MyControl creatLabelWithFrame:CGRectMake((IPHONE_WIDTH-220)/2, 0, 220, 40) text:@""];
    self.vacationTime.textAlignment=NSTextAlignmentCenter;
    [userInfoView addSubview:self.vacationTime];
    
    //假期时长提示
    self.vacationTimeButton=[MyControl creatButtonWithFrame:CGRectMake(IPHONE_WIDTH-58, 7.5, 25, 25) target:self sel:@selector(vacationTimeButtonClick) tag:102 image:@"k_tishi@2x" title:nil];
    self.vacationTimeButton.hidden=YES;
    [userInfoView addSubview:self.vacationTimeButton];
    
    //制度按钮
    self.systemButton=[MyControl creatButtonWithFrame:CGRectMake(IPHONE_WIDTH-58, 0, 50, 40) target:self sel:@selector(systemButtonClick) tag:101 image:nil title:@"制度"];
    self.systemButton.hidden=YES;
    [userInfoView addSubview:_systemButton];
    
    //创建列表
    _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 40, IPHONE_WIDTH, IPHONE_HEIGHT-40-64) style:UITableViewStyleGrouped];
    //_myTableView.backgroundColor=[UIColor redColor];
    _tableView.delegate=self;
    _tableView.dataSource=self;
    _tableView.tag=110;
    _tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    _tableView.showsVerticalScrollIndicator=NO;
    _tableView.showsHorizontalScrollIndicator=NO;
    _tableView.bounces=NO;
    //[self addTableViewUpdateRefresh:_tableView BindingIdentity:@""];
    //    [self addTableViewLoadMoreData:_tableView BindingIdentity:@""];
    [self.view addSubview:_tableView];
    [self addTableViewFootView];
    
//    DatePickerView *date=[[DatePickerView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, IPHONE_HEIGHT)];
//    [[[UIApplication sharedApplication].delegate window] addSubview:date];
}

- (void)addTableViewFootView{
    //添加提交和存草稿button
    UIView *footView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, 80)];
    footView.backgroundColor=[UIColor clearColor];
    
    NSArray *title=@[@"提交",@"存草稿"];
    CGFloat buttonWidth=(IPHONE_WIDTH-(title.count+1)*10)/title.count;
    for (int i=0; i<title.count; i++) {
        UIButton *submitButton=[MyControl creatButtonWithFrame:CGRectMake(10*(i+1)+buttonWidth*i,20, buttonWidth, 40) target:self sel:@selector(submitClick:) tag:120+i image:nil title:title[i]];
        submitButton.layer.masksToBounds=YES;
        submitButton.layer.cornerRadius=5;
        [submitButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        if (i==0) {
            submitButton.backgroundColor=COLOR_MIDBLUE;
        }else{
            submitButton.backgroundColor=[UIColor orangeColor];
        }
        [footView addSubview:submitButton];
    }
    _tableView.tableFooterView=footView;
}

#pragma mark -制度弹出框

- (void)creatPromptView{
    NSString *message=@"";
    for (int i=0; i<_institutionListModel.dataArr.count; i++) {
        InstitutionListModel *model=_institutionListModel.dataArr[i];
        NSString *msg=[NSString stringWithFormat:@"%d . %@\n",i+1,model.institution];
        message=[message stringByAppendingString:msg];
    }
    _promptView=[[PromptView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, IPHONE_HEIGHT) title:@"请假规则" message:message prompt:@"知道了,下次不在提醒" isHidePrompt:NO submitTitle:@"确定"];
    [[[UIApplication sharedApplication].delegate window]addSubview:_promptView];
}

#pragma mark -制度按钮点击
- (void)systemButtonClick{
    NSString *message=@"";
    for (int i=0; i<_institutionListModel.dataArr.count; i++) {
        InstitutionListModel *model=_institutionListModel.dataArr[i];
        NSString *msg=[NSString stringWithFormat:@"%d . %@\n",i+1,model.institution];
        message=[message stringByAppendingString:msg];
    }
    _promptView=[[PromptView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, IPHONE_HEIGHT) title:[NSString stringWithFormat:@"%@制度",_navaTitle] message:message prompt:@"知道了,下次不在提醒" isHidePrompt:YES submitTitle:@"知道了"];
    [[[UIApplication sharedApplication].delegate window]addSubview:_promptView];
}

#pragma mark -年假获取成功

- (void)getPersonalDaysInfoSuccess{
    
}


#pragma mark - TableViewDelagate

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section==1) {
        return 4;
    }else if (section==2){
        return self.addWorkPersonArr.count+1;
    }
    return 1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section==0) {
        NSString *cellID=@"DutyBasicTableViewCell";
        DutyBasicTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
        if (!cell) {
            cell=[[DutyBasicTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
        }
        cell.myTitleLabel.text=@"申  请  人 :";
        self.userTitleLabel=cell.myTitleLabel;
        cell.messageLabel.text=[NSString stringWithFormat:@"%@ ( %@ )",[LZXHelper getUserName],[LZXHelper getUserDepartName]];
        return cell;
    }else if(indexPath.section==1){
        if (indexPath.row==3) {
            NSString *cellID=@"ReasonTextTableViewCell";
            ReasonTextTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
            if (!cell) {
                cell=[[ReasonTextTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID title:@" 请填/选请假事由 : " noticeStr:nil];
                cell.selectionStyle=UITableViewCellSelectionStyleNone;
            }
            self.reasonTextView=cell.reasonTextView;
            self.reasonTextView.delegate=self;
            self.reasonTitleLabel=cell.myTitleLabel;
            return cell;
        }else{
            NSString *cellID=@"DutyBasicTableViewCell1";
            DutyBasicTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
            if (!cell) {
                cell=[[DutyBasicTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
                cell.selectionStyle=UITableViewCellSelectionStyleNone;
                [cell.signButton addTarget:self action:@selector(signButtonClick:) forControlEvents:UIControlEventTouchUpInside];
            }
            
            //保存疑问按钮
            if (indexPath.row==0) {
                self.beginSignButton=cell.signButton;
                self.beginTitleLabel=cell.myTitleLabel;
            }else if (indexPath.row==1){
                self.endSignButton=cell.signButton;
                self.endTitleLabel=cell.myTitleLabel;
            }
            if (indexPath.row<3) {
                cell.myTitleLabel.text=_titleArr[indexPath.row];
                cell.messageLabel.text=_messageArr[indexPath.row];
            }
            if (indexPath.row==0||indexPath.row==1) {
                cell.arrowImageView.hidden=NO;
                if ([cell.messageLabel.text isEqualToString:@"点击选择"]) {
                    cell.messageLabel.textColor=[UIColor lightGrayColor];
                }else{
                    cell.messageLabel.textColor=[UIColor blackColor];
                }
                
            }
            if (indexPath.row==2) {
                self.holidayCountLabel=cell.messageLabel;
                self.holidaysTitleLabel=cell.myTitleLabel;
            }
            return cell;
            
        }
    }else{
        if (indexPath.row==0) {
            NSString *cellID=@"CenterLabelTableViewCell";
            CenterLabelTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
            if (!cell) {
                cell=[[CenterLabelTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
                cell.selectionStyle=UITableViewCellSelectionStyleNone;
            }
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            cell.myTitle.text=@"点击此处添加工作委托";
            return cell;
        }else{
            NSString *cellID=@"AddPersonListTableViewCell";
            AddPersonListTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
            if (!cell) {
                cell=[[AddPersonListTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
                cell.selectionStyle=UITableViewCellSelectionStyleNone;
            }
            DepartPersonListModel *model=self.addWorkPersonArr[indexPath.row-1];
            cell.myTitleLabel.text=model.personName;
            cell.messageLabel.text=[NSString stringWithFormat:@"%@ 至 %@",model.beginStr,model.endStr];
            return cell;
        }
    }
    //    [cell.headImageView setImage:[UIImage imageNamed:_imageArr[indexPath.section][indexPath.row]]];
    //    cell.myTitle.text=_titleArr[indexPath.section][indexPath.row];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [self.reasonTextView resignFirstResponder];
    if (indexPath.section==1) {
        //选择开始和结束时间执行这里
        if (indexPath.row==0||indexPath.row==1){
            NSString *dateStr=nil;
            if (indexPath.row==0) {
                if (self.beginStr) {
                    dateStr=self.beginStr;
                }else if (self.endStr){
                    dateStr=self.endStr;
                }
            }
            if (indexPath.row==1) {
                if (self.endStr) {
                    dateStr=self.endStr;
                }else if (self.beginStr){
                    dateStr=self.beginStr;
                }
            }
            DatePickerView *datePickerView=[[DatePickerView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, IPHONE_HEIGHT)nowDateStr:dateStr];
            __weak NSMutableArray *myMessageArr=_messageArr;
            __weak UITableView *myTableView=_tableView;
            __weak DutyParentsViewController *mySelf=self;
            datePickerView.sureBlock=^(NSString *timeStr){
                if (indexPath.row==0) {
                    //如果是选择开始时间
                    //先判断有没有结束时间,如果有要进行比对
                    if (mySelf.endStr) {
                        if (![mySelf compareOneTime:timeStr withAnotherTime:mySelf.endStr]) {
                            [LZXHelper postMessageWithText:@"请假结束时间应该在请假开始时间之后!" View:mySelf.view];
                        }
                        [mySelf getVacateDaysOnlyRequest];
                    }
                    if (mySelf.dutyType==ApplyHoliday) {
                        //如果是请假
                        if ([mySelf compareTime:timeStr]) {
                            //比现在的时间早
                            [LZXHelper postAlertViewControllerWithTitle:@"您选择的请假开始时间早于今天,要补假吗?" message:nil cancelButtonTitle:@"选错时间了" otherButtonTitle:@"去补假" cancelEvent:^{
                                
                            } otherEvent:^{
                                mySelf.dutyType=1;
                                
                                [mySelf setNavigationTitle:[mySelf.navaTitle stringByAppendingString:@"补假申请"]];
                                
                            } viewController:mySelf];
                        }else{
                            //比现在的时间晚
                            mySelf.beginStr=[timeStr copy];
                            [mySelf setLabelBorderColorWithLabel:mySelf.beginTitleLabel color:[UIColor clearColor]];
                            [myMessageArr replaceObjectAtIndex:indexPath.row withObject:timeStr];
                            [myTableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
                            [mySelf getTimeControlRequestWithBeginTime:[timeStr copy]endTime:nil type:@"Begin"];
                        }
                        
                    }else{
                        //如果是补假
                        if ([mySelf compareTime:timeStr]){
                            //比现在的时间早
                            mySelf.beginStr=[timeStr copy];
                            [mySelf setLabelBorderColorWithLabel:mySelf.beginTitleLabel color:[UIColor clearColor]];
                            [myMessageArr replaceObjectAtIndex:indexPath.row withObject:timeStr];
                            [myTableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
                            [mySelf getTimeControlRequestWithBeginTime:[timeStr copy]endTime:nil type:@"Begin"];
                        }else{
                            //比现在的时间晚
                            [LZXHelper postAlertViewControllerWithTitle:@"您选择的请假开始时间晚于今天,要请假吗?" message:nil cancelButtonTitle:@"选错时间了" otherButtonTitle:@"去请假" cancelEvent:^{
                                
                            } otherEvent:^{
                                mySelf.dutyType=0;
                                [mySelf setNavigationTitle:[mySelf.navaTitle stringByAppendingString:@"申请"]];
                            } viewController:mySelf];
                        }
                    }
                    
                }else{
                    //点击结束时间
                    mySelf.endStr=[timeStr copy];
                    [mySelf setLabelBorderColorWithLabel:mySelf.endTitleLabel color:[UIColor clearColor]];
                    [myMessageArr replaceObjectAtIndex:indexPath.row withObject:timeStr];
                    [myTableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
                    [mySelf getVacateDaysOnlyRequest];
                    [mySelf getTimeControlRequestWithBeginTime:mySelf.beginStr endTime:[timeStr copy] type:@"End"];
                }
            };
            [[[UIApplication sharedApplication].delegate window] addSubview:datePickerView];
        }
    }else if (indexPath.section==2&&indexPath.row==0){
        if (!self.beginStr) {
            [LZXHelper postMessageWithText:@"请假开始时间不能为空!" View:self.view];
            return;
        }
        if (!self.endStr) {
            [LZXHelper postMessageWithText:@"请假结束时间不能为空!" View:self.view];
            return;
        }
        //跳转到委托人选择页面
        AddWorkPersonViewController *person=[AddWorkPersonViewController new];
        person.dutyType=self.dutyType;
        person.beginStr=self.beginStr;
        person.endStr=self.endStr;
        __weak UITableView *myTableView=_tableView;
        person.myBlock=^(DepartPersonListModel *model){
            [self.addWorkPersonArr addObject:model];
            [myTableView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section]  withRowAnimation:UITableViewRowAnimationFade];
        };
        [self.navigationController pushViewController:person animated:YES];
    }else{
        
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    //如果是添加工作委托
    if (indexPath.section==2) {
        if (indexPath.row==0) {
            return 50;
        }else{
            return 64;
        }
        //请假内容
    }else if (indexPath.section==1){
        if (indexPath.row==3) {
            return 100;
        }else{
            return 50;
        }
    }
    return 50;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 20;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 1;
}

//开启编辑模式
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section==2&&indexPath.row!=0) {
        return YES;
    }
    return NO;
}
-(NSString*)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{
    return @"删除";
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    // 从数据源中删除
    [self.addWorkPersonArr removeObjectAtIndex:indexPath.row-1];
    // 从列表中删除
    [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}

#pragma mark -时间疑问按钮点击
- (void)signButtonClick:(UIButton *)button{
    if (_beginSignButton==button) {
        PromptView *promptView=[[PromptView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, IPHONE_HEIGHT) title:@"" message:[self getNormalStringWithMessage:_beginTimeModel.myMessage] prompt:nil isHidePrompt:YES submitTitle:@"知道了"];
        [[[UIApplication sharedApplication].delegate window]addSubview:promptView];
    }else{
        PromptView *promptView=[[PromptView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, IPHONE_HEIGHT) title:@"" message:[self getNormalStringWithMessage:_endTimeModel.myMessage] prompt:nil isHidePrompt:YES submitTitle:@"知道了"];
        [[[UIApplication sharedApplication].delegate window]addSubview:promptView];
    }
}

#pragma mark -提交和存草稿按钮
- (void)submitClick:(UIButton *)button{
    [self.view endEditing:YES];
    if (button.tag==120) {
//        if (self.vacateBillId) {
//            /*state=0 草稿
//            state=1 待审批
//            state=2 审批驳回
//            state=3 待核销
//            state=4 销假驳回
//            state=5 待核销
//            state=6 核销成功
//             */
//            [self submitApplyRequestWithState:@"2"];
//        }else{
//            //提交
            [self submitApplyRequestWithState:@"1"];
//        }

    }else{
        //草稿
        [self submitApplyRequestWithState:@"0"];
    }
}

#pragma mark -休假时长提示

- (void)vacationTimeButtonClick{
    [LZXHelper postDetailMessageWithText:_applyStr View:[[UIApplication sharedApplication].delegate window]];
}

- (void)backClick{
    if ([_timer isValid]) {
        [_timer invalidate];
        _timer=nil;
    }
    [LZXHelper postAlertViewControllerWithTitle:[NSString stringWithFormat:@"是否放弃%@?",[_navaTitle stringByAppendingString:@"申请"]] message:nil cancelButtonTitle:@"放弃" otherButtonTitle:@"继续编辑" cancelEvent:^{
        [super backClick];
    } otherEvent:^{
        
    } viewController:self];
}

#pragma mark -定时器刷新函数
- (void)timerFunc

{
    if (_second>0) {
        _second--;
    }else{
        _minute--;
        _second=59;
    }
    if (_minute<=0) {
        _timeLabel.textColor=[UIColor redColor];
    }
    _timeLabel.text=[NSString stringWithFormat:@"%02ld:%02ld",_minute,_second];
    //[self setRightNavigation:];
    if (_minute==0&&_second==0) {
        [self theTimeOut];
        [_timer setFireDate:[NSDate distantFuture]];
    }
}

#pragma mark -计时器函数
- (void)theTimeOut{
    //NSLog(@"时间到了!");
    DutyParentsViewController *mySelf=self;
    [LZXHelper postAlertViewControllerWithTitle:@"已超出时间" message:@"请点击'关闭'退出当前页面" cancelButtonTitle:nil otherButtonTitle:@"关闭" cancelEvent:^{
        
    } otherEvent:^{
        if ([_timer isValid]) {
            [_timer invalidate];
            _timer=nil;
        }
        [mySelf.navigationController popViewControllerAnimated:YES];
    } viewController:self];
}






//右边导航栏
- (void)setRightNavigation:(NSString *)title{
    //
    if (self.navigationItem.rightBarButtonItem) {
        self.navigationItem.rightBarButtonItem.title=title;
    }else{
        _timeLabel=[MyControl creatLabelWithFrame:CGRectMake(0, 0, 60, 44) text:@""];
        //_timeLabel.backgroundColor=[UIColor redColor];
        _timeLabel.textAlignment=NSTextAlignmentRight;
        _timeLabel.textColor=[UIColor whiteColor];
        UIBarButtonItem *item=[[UIBarButtonItem alloc]initWithCustomView:_timeLabel];
        [item setTintColor:[UIColor whiteColor]];
        self.navigationItem.rightBarButtonItem=item;
    }
    
    //    [self.navigationItem.rightBarButtonItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont boldSystemFontOfSize:13], NSFontAttributeName, [UIColor whiteColor], NSFontAttributeName, nil] forState:UIControlStateNormal];
}




#pragma mark -获取单项管控规则

- (void)getSingleControlRequest{
    [LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:self.view];
    
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content></content>",[LZXHelper getSessionID]];
    // __weak AddressBookViewController *mySelf=self;
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:getSingleControl soapBody:soap success:^(id responseObject) {
        [LZXHelper hideLoadViewWithView:self.view];
        
        //解析数据
        BasicModel *_model=[[BasicModel alloc]initWithResponse:responseObject];
        if ([_model.code isEqualToString:@"200"]) {
            //            NSDictionary *dataDict=responseObject[@"retContent"];
            //            _dateStr=[dataDict[@"serviceTime"] copy];
            
        }else if([_model.code isEqualToString:@"220"]){
            [LZXHelper postMessageWithText:_model.msg View:self.view];
        }
    } failure:^(NSError *error) {
        [LZXHelper hideLoadViewWithView:self.view];
    }];
}

#pragma mark -快捷输入请求

- (void)getCauseListRequest{
    [LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:self.view];
    
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content></content>",[LZXHelper getSessionID]];
    // __weak AddressBookViewController *mySelf=self;
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:getCauseList soapBody:soap success:^(id responseObject) {
        [LZXHelper hideLoadViewWithView:self.view];
        
        //解析数据
        BasicModel *_model=[[BasicModel alloc]initWithResponse:responseObject];
        if ([_model.code isEqualToString:@"200"]) {
            //            NSDictionary *dataDict=responseObject[@"retContent"];
            //            _dateStr=[dataDict[@"serviceTime"] copy];
            
        }else if([_model.code isEqualToString:@"220"]){
            [LZXHelper postMessageWithText:_model.msg View:self.view];
        }
    } failure:^(NSError *error) {
        [LZXHelper hideLoadViewWithView:self.view];
    }];
}

#pragma mark -加班和年假天数请求

- (void)getPersonalDaysInfoRequest{
    NSDictionary *dict=@{
                         @"type":@"0"
                         };
    
    //   字典转json
    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
    NSString* str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    //拼接soap字符串
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content>%@</content>",[LZXHelper getSessionID],str];
    // __weak AddressBookViewController *mySelf=self;
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:getPersonalDaysInfo soapBody:soap success:^(id responseObject) {
        //[LZXHelper hideLoadViewWithView:self.view];
        
        //解析数据
        BasicModel *model=[[BasicModel alloc]initWithResponse:responseObject];
        if ([model.code isEqualToString:@"200"]) {
            NSDictionary *dataDict=responseObject[@"retContent"];
            self.personYearDays=dataDict[@"days"];
            [self getPersonalDaysInfoSuccess];
            //            _dateStr=[dataDict[@"serviceTime"] copy];
            
        }else if([model.code isEqualToString:@"220"]){
            [LZXHelper postMessageWithText:model.msg View:self.view];
        }
    } failure:^(NSError *error) {
        [LZXHelper hideLoadViewWithView:self.view];
    }];
}

#pragma mark -获取倒计时间请求

- (void)getCountdownTimeInfoRequest{
    
    NSDictionary *dict=@{
                         @"businessCode":_businessCode?_businessCode:@"",
                         @"LeaveTypePK":_keywordId?_keywordId:@"",
                         @"type":@"1"
                         };
    
    //   字典转json
    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
    NSString* str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    //拼接soap字符串
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content>%@</content>",[LZXHelper getSessionID],str];
    // __weak AddressBookViewController *mySelf=self;
    [LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:self.view];
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:getCountdownTimeInfo soapBody:soap success:^(id responseObject) {
        [LZXHelper hideLoadViewWithView:self.view];
        
        //解析数据
        BasicModel *_model=[[BasicModel alloc]initWithResponse:responseObject];
        if ([_model.code isEqualToString:@"200"]) {
            NSDictionary *dict=responseObject[@"retContent"];
            NSInteger holidayCount=[dict[@"TimeLength"] integerValue];
            if (holidayCount%60>0) {
                //初始化时间
                _minute=holidayCount/60;
                //_minute=0;
                _second=holidayCount%60;
            }else{
                //初始化时间
                _minute=holidayCount/60-1;
                //_minute=0;
                _second=60;
            }
            _timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(timerFunc) userInfo:nil repeats:YES];
        }else if([_model.code isEqualToString:@"220"]){
            [LZXHelper postMessageWithText:_model.msg View:self.view];
        }
    } failure:^(NSError *error) {
        [LZXHelper hideLoadViewWithView:self.view];
    }];
}

//#pragma mark -获取人员列表
//
//- (void)getDepartPersonListRequest{
//    [LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:self.view];
//    
//    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content></content>",[LZXHelper getSessionID]];
//    // __weak AddressBookViewController *mySelf=self;
//    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:getDepartPersonList soapBody:soap success:^(id responseObject) {
//        [LZXHelper hideLoadViewWithView:self.view];
//        
//        //解析数据
//        BasicModel *_model=[[BasicModel alloc]initWithResponse:responseObject];
//        if ([_model.code isEqualToString:@"200"]) {
//            //            NSDictionary *dataDict=responseObject[@"retContent"];
//            //            _dateStr=[dataDict[@"serviceTime"] copy];
//            
//        }else if([_model.code isEqualToString:@"220"]){
//            [LZXHelper postMessageWithText:_model.msg View:self.view];
//        }
//    } failure:^(NSError *error) {
//        [LZXHelper hideLoadViewWithView:self.view];
//    }];
//}

#pragma mark -获取制度详细信息请求

- (void)getManagementInfoRequest{
    NSDictionary *dict=@{
                         @"businessCode":_businessCode?_businessCode:@"",
                         };
    
    //   字典转json
    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
    NSString* str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    //拼接soap字符串
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content>%@</content>",[LZXHelper getSessionID],str];
    //[LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:self.view];
    // __weak AddressBookViewController *mySelf=self;
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:getManagementInfo soapBody:soap success:^(id responseObject) {
        //[LZXHelper hideLoadViewWithView:self.view];
        
        //解析数据
        _institutionListModel=[[InstitutionListModel alloc]initWithResponse:responseObject];
        if ([_institutionListModel.code isEqualToString:@"200"]) {
            _systemButton.hidden=NO;
             
        }else if([_institutionListModel.code isEqualToString:@"220"]){
            //[LZXHelper postMessageWithText:_model.msg View:self.view];
        }
    } failure:^(NSError *error) {
        //[LZXHelper hideLoadViewWithView:self.view];
    }];
}

#pragma mark -选择开始时间

- (void)getTimeControlRequestWithBeginTime:(NSString *)beginTime endTime:(NSString *)endTime type:(NSString *)type{
    NSDictionary *dict=@{
                         @"businessCode":_businessCode?_businessCode:@"",
                         @"beginTime":beginTime?beginTime:@"",
                         @"endTime":endTime?endTime:@"",
                         @"timeType":type
                         };
    
    //   字典转json
    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
    NSString* str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    //拼接soap字符串
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content>%@</content>",[LZXHelper getSessionID],str];
    //[LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:self.view];
    // __weak AddressBookViewController *mySelf=self;
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:getTimeControl soapBody:soap success:^(id responseObject) {
        //[LZXHelper hideLoadViewWithView:self.view];
        BasicModel *model=[[BasicModel alloc]initWithResponse:responseObject];
        //解析数据
        if ([model.code isEqualToString:@"200"]) {
            if ([type isEqualToString:@"Begin"]) {
                _beginTimeModel=[[BeginTimeModel alloc]initWithResponse:responseObject];
                if (_beginTimeModel.myMessage.length>0) {
                    _beginSignButton.hidden=NO;
                    PromptView *promptView=[[PromptView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, IPHONE_HEIGHT) title:@"" message:[self getNormalStringWithMessage:_beginTimeModel.myMessage] prompt:nil isHidePrompt:YES submitTitle:@"知道了"];
                    [[[UIApplication sharedApplication].delegate window]addSubview:promptView];
                }
            }else{
                _endTimeModel=[[BeginTimeModel alloc]initWithResponse:responseObject];
                if (_endTimeModel.myMessage.length>0) {
                    _endSignButton.hidden=NO;
                    PromptView *promptView=[[PromptView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, IPHONE_HEIGHT) title:@"" message:[self getNormalStringWithMessage:_endTimeModel.myMessage] prompt:nil isHidePrompt:YES submitTitle:@"知道了"];
                    [[[UIApplication sharedApplication].delegate window]addSubview:promptView];
                }
            }
        }else if([model.code isEqualToString:@"220"]){
            [LZXHelper postMessageWithText:model.msg View:self.view];
        }
    } failure:^(NSError *error) {
        //[LZXHelper hideLoadViewWithView:self.view];
    }];
}

#pragma mark -获取请假天数

- (void)getVacateDaysOnlyRequest{
    if (!_beginStr) {
        [LZXHelper postMessageWithText:@"请假开始时间不能为空!" View:self.view];
        return;
    }
    if (![self compareOneTime:_beginStr withAnotherTime:_endStr]) {
        [self setLabelBorderColorWithLabel:_endTitleLabel color:[UIColor redColor]];
        [LZXHelper postMessageWithText:@"请假结束时间应该在请假开始时间之后!" View:self.view];
        return;
    }

    NSDictionary *dict=@{
                         @"businessCode":_businessCode?_businessCode:@"",
                         @"vacateBeginTime":_beginStr?_beginStr:@"",
                         @"vacateEndTime":_endStr?_endStr:@"",
                         @"LeaveTypePK":_keywordId?_keywordId:@"",
                         @"vacateBillId":@""
                         };
    
    //   字典转json
    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
    NSString* str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    //拼接soap字符串
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content>%@</content>",[LZXHelper getSessionID],str];
    //[LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:self.view];
    // __weak AddressBookViewController *mySelf=self;
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:getVacateDaysOnly soapBody:soap success:^(id responseObject) {
        //[LZXHelper hideLoadViewWithView:self.view];
        
        //解析数据
        BasicModel *model=[[BasicModel alloc]initWithResponse:responseObject];
        if ([model.code isEqualToString:@"200"]) {
            NSDictionary *dict=responseObject[@"retContent"];
            _applyStr=dict[@"strflow"];
            _holidayCount=dict[@"vacateDays"];
            if (_dutyType==ApplyHoliday) {
                _vacationTime.text=[NSString stringWithFormat:@"%@%@%@天",[LZXHelper getUserName],_navaTitle,_holidayCount];
            }else{
                _vacationTime.text=[NSString stringWithFormat:@"%@%@%@天",[LZXHelper getUserName],[_navaTitle stringByAppendingString:@"补假"],_holidayCount];
            }
            //[_vacationTime sizeToFit];
            //设置提示
            CGFloat labelWidth=[LZXHelper textWidthFromTextString:_vacationTime.text Height:20 fontSize:15];
            _vacationTimeButton.x=IPHONE_WIDTH/2+labelWidth/2+10;
            _vacationTimeButton.hidden=NO;
            if (![_holidayCount isEqualToString:@"0"]) {
                [LZXHelper postDetailMessageWithText:_applyStr View:[[UIApplication sharedApplication].delegate window]];
            }
            _holidayCountLabel.text=[NSString stringWithFormat:@"%@  天",_holidayCount];
        }else if([model.code isEqualToString:@"220"]){
            [LZXHelper postMessageWithText:model.msg View:self.view];
        }
    } failure:^(NSError *error) {
        //[LZXHelper hideLoadViewWithView:self.view];
    }];
}

#pragma mark -获取提交时的提示文字

- (void)submitApplyRequestWithState:(NSString *)state{
    //如果有必选项没填则需提示和标记出来
    if (!self.beginStr) {
        [LZXHelper postMessageWithText:@"请假开始时间不能为空!" View:self.view];
        [self setLabelBorderColorWithLabel:self.beginTitleLabel color:[UIColor redColor]];
        return;
    }else{
        [self setLabelBorderColorWithLabel:self.beginTitleLabel color:[UIColor clearColor]];
    }
    
    if (!self.endStr) {
        [LZXHelper postMessageWithText:@"请假结束时间不能为空!" View:self.view];
        [self setLabelBorderColorWithLabel:self.endTitleLabel color:[UIColor redColor]];
        return;
    }else{
        [self setLabelBorderColorWithLabel:self.endTitleLabel color:[UIColor clearColor]];
    }
    
//    if (![self compareOneTime:self.beginStr withAnotherTime:self.endStr]) {
//        [LZXHelper postMessageWithText:@"请假结束时间应该在请假开始时间之后!" View:self.view];
//        //[self setLabelBorderColorWithLabel:_beginTitleLabel with:[UIColor redColor]];
//        return;
//    }
    //    else{
    //        [self setLabelBorderColorWithLabel:_beginTitleLabel with:[UIColor redColor]];
    //    }
    if ([_beginTimeModel.isCanCommit isEqualToString:@"0"]||_beginTimeModel==nil) {
        [LZXHelper postMessageWithText:_beginTimeModel.myMessage View:self.view];
        [self setLabelBorderColorWithLabel:self.beginTitleLabel color:[UIColor redColor]];
        return;
    }else{
        [self setLabelBorderColorWithLabel:self.beginTitleLabel color:[UIColor clearColor]];
    }
    
    if ([_endTimeModel.isCanCommit isEqualToString:@"0"]||_endTimeModel==nil) {
        [LZXHelper postMessageWithText:_endTimeModel.myMessage View:self.view];
        [self setLabelBorderColorWithLabel:self.endTitleLabel color:[UIColor redColor]];
        return;
    }else{
        [self setLabelBorderColorWithLabel:self.endTitleLabel color:[UIColor clearColor]];
    }
    
    if (self.reasonTextView.text.length==0) {
        [LZXHelper postMessageWithText:@"请假事由不能为空!" View:self.view];
        [self setLabelBorderColorWithLabel:self.reasonTitleLabel color:[UIColor redColor]];
        return;
    }else{
        [self setLabelBorderColorWithLabel:self.reasonTitleLabel color:[UIColor clearColor]];
    }
    
    if ([_holidayCount isEqualToString:@"0"]||[_holidayCount isEqualToString:@"0.0"]||[_holidayCount isEqualToString:@"0.00"]||_holidayCount==nil) {
        [LZXHelper postMessageWithText:[NSString stringWithFormat:@"%@时长不能为0!",_navaTitle] View:self.view];
        return;
    }
    
    NSDictionary *dict=@{
                         @"BusinessCode":self.businessCode?self.businessCode:@"",
                         @"BeginTime":self.beginStr?self.beginStr:@"",
                         @"EndTime":self.endStr?self.endStr:@"",
                         @"LeaveTypePK":self.keywordId?self.keywordId:@"",
                         @"vacateBillId":@""
                         };
    
    //   字典转json
    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
    NSString* str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    //拼接soap字符串
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content>%@</content>",[LZXHelper getSessionID],str];
    //[LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:self.view];
    // __weak AddressBookViewController *mySelf=self;
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:IsOverLaped soapBody:soap success:^(id responseObject) {
        //[LZXHelper hideLoadViewWithView:self.view];
        
        //解析数据
        BasicModel *model=[[BasicModel alloc]initWithResponse:responseObject];
        __weak DutyParentsViewController *mySelf=self;
        if ([model.code isEqualToString:@"200"]) {
            NSDictionary *dict=responseObject[@"retContent"];
            if ([dict[@"IsOverLap"] isEqualToString:@"0"]) {
                [LZXHelper postAlertViewControllerWithTitle:dict[@"strDesc"] message:nil cancelButtonTitle:@"取消" otherButtonTitle:@"确定" cancelEvent:^{
                    
                } otherEvent:^{
                    if (mySelf.vacateBillId) {
                        [mySelf updateSickVacateInfoRequest];
                    }else{
                        [mySelf postSickVacateInfoRequestWith:state];
                    }
                } viewController:mySelf];
            }else{
                DateConflictView *date=[[DateConflictView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, IPHONE_HEIGHT) message:dict[@"strDesc"]];
                //确定回调函数
                date.promptTimeBlock=^(NSInteger selectNum){
                    mySelf.optionType=[NSString stringWithFormat:@"%ld",selectNum-1];
                    [mySelf postSickVacateInfoRequestWith:state];
                };
                //取消回调函数
                date.promptTimeCancelBlock=^(){
                    //_promptTimeView=nil;
                };
                [[[UIApplication sharedApplication].delegate window] addSubview:date];
            }
            
        }else if([model.code isEqualToString:@"220"]){
            [LZXHelper postMessageWithText:model.msg View:self.view];
        }
    } failure:^(NSError *error) {
        //[LZXHelper hideLoadViewWithView:self.view];
    }];
    
}
#pragma mark -提交请假信息

- (void)postSickVacateInfoRequestWith:(NSString *)state{
    NSDateFormatter *formatter=[[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    NSString *timeStr=[formatter stringFromDate:[NSDate date]];
    
    NSMutableArray *workArr=[NSMutableArray new];
    for (DepartPersonListModel *model in _addWorkPersonArr) {
        NSDictionary *dict=@{
                             @"entrustId":model.personId?model.personId:@"",
                              @"entrustContent":model.msgContent?model.msgContent:@"",
                              @"entrustBeginTime":model.beginStr?model.beginStr:@"",
                              @"entrustEndTime":model.endStr?model.endStr:@"",
                             };
        [workArr addObject:dict];
    }
    
    NSDictionary *dict=@{
                         @"BusinessCode":_businessCode?_businessCode:@"",
                         @"vacateBeginTime":_beginStr?_beginStr:@"",
                         @"vacateEndTime":_endStr?_endStr:@"",
                         @"vacateDays":_holidayCount?_holidayCount:@"",
                         @"LeaveTypePK":_keywordId?_keywordId:@"",
                         @"vacateBillId":self.vacateBillId?self.vacateBillId:@"",
                         @"BaseTypeId":self.BaseTypeId?self.BaseTypeId:@"",
                         @"OtherTypeId":@"",
                         @"empName":[LZXHelper getUserName]?[LZXHelper getUserName]:@"",
                         @"isEntrust":_addWorkPersonArr.count>0?@"1":@"0",
                         @"isState":state?state:@"",
                         @"optionType":self.optionType?self.optionType:@"",
                         @"rules":@"",
                         @"sendEmpId":@"",
                         @"serviceTime":self.serviceTime?self.serviceTime:timeStr,
                         @"vacateReason":_reasonTextView.text,
                         @"yearVacateReplaceDays":self.yearVacateReplaceDays?self.yearVacateReplaceDays:@"0",
                         @"workEntrustList":workArr
                         };
    
    //   字典转json
    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
    NSString* str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    //拼接soap字符串
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content>%@</content>",[LZXHelper getSessionID],str];
    [LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:self.view];
    // __weak AddressBookViewController *mySelf=self;
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:postSickVacateInfo soapBody:soap success:^(id responseObject) {
        [LZXHelper hideLoadViewWithView:self.view];
        
        //解析数据
        BasicModel *model=[[BasicModel alloc]initWithResponse:responseObject];
        //因为传回来的code类型不同  要做判断
        if ([state isEqualToString:@"0"]) {
            if ([model.code isEqualToString:@"200"]) {
                [LZXHelper postMessageWithText:model.msg View:[[UIApplication sharedApplication].delegate window]];
                if (self.vacateBillId) {
                    for (UIViewController *controller in self.navigationController.viewControllers) {
                        if ([controller isKindOfClass:[MyJobListViewController class]]) {
                            [self.navigationController popToViewController:controller animated:YES];
                        }
                    }
                }else{
                    [self.navigationController popViewControllerAnimated:YES];
                }
            }else if([model.code isEqualToString:@"220"]){
                [LZXHelper postMessageWithText:model.msg View:[[UIApplication sharedApplication].delegate window]];
            }
        }else{
            if ([model.code isEqualToString:@"220"]) {
                [LZXHelper postMessageWithText:model.msg View:[[UIApplication sharedApplication].delegate window]];
                if (self.vacateBillId) {
                    for (UIViewController *controller in self.navigationController.viewControllers) {
                        if ([controller isKindOfClass:[MyJobListViewController class]]) {
                            [self.navigationController popToViewController:controller animated:YES];
                        }
                    }
                }else{
                    [self.navigationController popViewControllerAnimated:YES];
                }
            }else if([model.code isEqualToString:@"200"]){
                [LZXHelper postMessageWithText:model.msg View:[[UIApplication sharedApplication].delegate window]];
            }
        }
    } failure:^(NSError *error) {
        //[LZXHelper hideLoadViewWithView:self.view];
    }];
}

#pragma mark -更新病假申请提交接口

- (void)updateSickVacateInfoRequest{
    NSDateFormatter *formatter=[[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    NSString *timeStr=[formatter stringFromDate:[NSDate date]];
    
    NSMutableArray *workArr=[NSMutableArray new];
    for (DepartPersonListModel *model in _addWorkPersonArr) {
        NSDictionary *dict=@{
                             @"entrustId":model.personId?model.personId:@"",
                             @"entrustContent":model.msgContent?model.msgContent:@"",
                             @"entrustBeginTime":model.beginStr?model.beginStr:@"",
                             @"entrustEndTime":model.endStr?model.endStr:@"",
                             };
        [workArr addObject:dict];
    }
    //{"BaseTypeId":"","BusinessCode":"SJ0002","LeaveTypePK":"0002","OtherTypeId":"","SignDrId":"","cardInfoId":"","empName":"于航","infoId":"4034","isEntrust":"1","isState":"1","optionType":"","rules":"","sendEmpId":"","serviceTime":"2016-12-22 11:06:40","taskId":"2531","vacateBeginTime":"2016-12-22 13:00","vacateBillId":"LNJJ-HR-KQ-SI-201612220001","vacateDays":"0.33","vacateEndTime":"2016-12-22 16:00","vacateReason":"取东西","workEntrustList":[{"entrustBeginTime":"2016-12-22 13:00","entrustContent":"帮忙","entrustEndTime":"2016-12-22 16:00","entrustId":"155"}],"yearVacateReplaceDays":"0.00"}
    NSDictionary *dict=@{
                         @"BusinessCode":_businessCode?_businessCode:@"",
                         @"vacateBeginTime":_beginStr?_beginStr:@"",
                         @"vacateEndTime":_endStr?_endStr:@"",
                         @"vacateDays":_holidayCount?_holidayCount:@"",
                         @"LeaveTypePK":_keywordId?_keywordId:@"",
                         @"vacateBillId":self.vacateBillId?self.vacateBillId:@"",
                         @"BaseTypeId":self.BaseTypeId?self.BaseTypeId:@"",
                         @"OtherTypeId":@"",
                         @"empName":[LZXHelper getUserName]?[LZXHelper getUserName]:@"",
                         @"isEntrust":_addWorkPersonArr.count>0?@"1":@"0",
                         @"isState":@"1",
                         @"optionType":self.optionType?self.optionType:@"",
                         @"rules":@"",
                         @"sendEmpId":@"",
                         @"serviceTime":self.serviceTime?self.serviceTime:timeStr,
                         @"vacateReason":_reasonTextView.text,
                         @"infoId":self.infoId?self.infoId:@"",
                         @"taskId":self.taskId?self.taskId:@"",
                         @"SignDrId":@"",
                         @"cardInfoId":self.cardInfoId?self.cardInfoId:@"",
                         @"yearVacateReplaceDays":self.yearVacateReplaceDays?self.yearVacateReplaceDays:@"0",
                         @"workEntrustList":workArr
                         };
    
    //   字典转json
    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
    NSString* str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    //拼接soap字符串
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content>%@</content>",[LZXHelper getSessionID],str];
    [LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:self.view];
    // __weak AddressBookViewController *mySelf=self;
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:updateSickVacateInfo soapBody:soap success:^(id responseObject) {
        [LZXHelper hideLoadViewWithView:self.view];
        
        //解析数据
        BasicModel *model=[[BasicModel alloc]initWithResponse:responseObject];
            if ([model.code isEqualToString:@"220"]) {
                [LZXHelper postMessageWithText:model.msg View:[[UIApplication sharedApplication].delegate window]];
                if (self.vacateBillId) {
                    for (UIViewController *controller in self.navigationController.viewControllers) {
                        if ([controller isKindOfClass:[MyJobListViewController class]]) {
                            [self.navigationController popToViewController:controller animated:YES];
                        }
                    }
                }else{
                    [self.navigationController popViewControllerAnimated:YES];
                }
            }else if([model.code isEqualToString:@"200"]){
                [LZXHelper postMessageWithText:model.msg View:[[UIApplication sharedApplication].delegate window]];
            }
    } failure:^(NSError *error) {
        //[LZXHelper hideLoadViewWithView:self.view];
    }];
}



#pragma mark -获取可选项列表
- (void)getDropListRequestWithdataSwith:(NSString *)dataSwith isDetailList:(BOOL)isDetailList{
    
    NSDictionary *dict=@{
                         @"dataSwith":dataSwith?dataSwith:@"",
                         };
    
    //   字典转json
    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
    NSString* str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    //拼接soap字符串
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content>%@</content>",[LZXHelper getSessionID],str];
    // __weak AddressBookViewController *mySelf=self;
    //[LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:self.view];
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:getDropList soapBody:soap success:^(id responseObject) {
        //[LZXHelper hideLoadViewWithView:self.view];
        
        //解析数据
        BasicModel *_model=[[BasicModel alloc]initWithResponse:responseObject];
        if ([_model.code isEqualToString:@"200"]) {
            if (isDetailList) {
                _dropDetailListModel=[[DutyDropModel alloc]initWithResponse:responseObject];
                [self dropDetailListModelRequestSuccess];
            }else{
                _dropListModel=[[DutyDropModel alloc]initWithResponse:responseObject];
                [self dropListModelRequestSuccess];
            }
            
        }else if([_model.code isEqualToString:@"220"]){
            [LZXHelper postMessageWithText:_model.msg View:self.view];
        }
    } failure:^(NSError *error) {
        //[LZXHelper hideLoadViewWithView:self.view];
    }];
}

#pragma mark -已核销查看页面请假信息
- (void)getVacateInfoRequestWithVacateBillId:(NSString *)vacateBillId{
    
    NSDictionary *dict=@{
                         @"vacateBillId":vacateBillId?vacateBillId:@"",
                         };
    
    //   字典转json
    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
    NSString* str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    //拼接soap字符串
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content>%@</content>",[LZXHelper getSessionID],str];
    // __weak AddressBookViewController *mySelf=self;
    //[LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:self.view];
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:getVacateInfo soapBody:soap success:^(id responseObject) {
        //[LZXHelper hideLoadViewWithView:self.view];
        
        //解析数据
        BasicModel *model=[[BasicModel alloc]initWithResponse:responseObject];
        if ([model.code isEqualToString:@"200"]) {
            [self getVacateInfoRequestSuccess:responseObject];
        }else if([model.code isEqualToString:@"220"]){
            [LZXHelper postMessageWithText:model.msg View:self.view];
        }
    } failure:^(NSError *error) {
        //[LZXHelper hideLoadViewWithView:self.view];
    }];
}

#pragma mark -页面请假信息请求成功
- (void)getVacateInfoRequestSuccess:(id)responseObject{
    //解析数据
    self.infoModel=[[VacateInfoModel alloc]initWithResponse:responseObject];
    self.beginStr=self.infoModel.vacateBeginTime;
    self.endStr=self.infoModel.vacateEndTime;
    self.taskId=self.infoModel.TaskID;
    NSString *dayStr=[NSString stringWithFormat:@"%@  天",self.infoModel.vacateDays];
    self.reasonTextView.text=self.infoModel.vacateReason;
    self.reasonTextView.textColor=[UIColor blackColor];
    //替换数据
    _messageArr=[NSMutableArray arrayWithArray:@[@"",self.beginStr?self.beginStr:@"点击选择",self.endStr?self.endStr:@"点击选择",dayStr]];
    //保存委托人
    if (self.infoModel.workEntrustList.count>0) {
        for (int i=0; i<self.infoModel.workEntrustList.count; i++) {
            VacateInfoModel *model=self.infoModel.workEntrustList[i];
            DepartPersonListModel *personModel=[DepartPersonListModel new];
            personModel.personId=model.ids;
            personModel.personName=model.entrustMan;
            personModel.beginStr=model.entrustBeginTime;
            personModel.endStr=model.entrustEndTime;
            personModel.msgContent=model.taskDescribe;
            [self.addWorkPersonArr addObject:personModel];
        }
    }
    [self getTimeControlRequestWithBeginTime:self.beginStr endTime:nil type:@"Begin"];
    [self getTimeControlRequestWithBeginTime:self.beginStr endTime:self.endStr type:@"End"];
    [self getVacateDaysOnlyRequest];
    [_tableView reloadData];
}


#pragma mark -请假类型列表请求成功

- (void)dropListModelRequestSuccess{
    
}

#pragma mark -请假类型详细列表请求成功

- (void)dropDetailListModelRequestSuccess{
    
}


#pragma mark - 整理字符串

- (NSString *)getNormalStringWithMessage:(NSString *)message{
    if (message==nil||message.length==0) {
        return nil;
    }
    //去掉前面的|
    if ([[message substringToIndex:1]isEqualToString:@"|"]) {
        message=[message substringFromIndex:1];
    }
    //去掉最后面的|
    if ([[message substringFromIndex:message.length-1]isEqualToString:@"|"]) {
        message =[message substringToIndex:message.length-1];
    }
    //切割
    NSArray *messageArr=[message componentsSeparatedByString:@"|"];
    NSString *newMessage=@"";
    if (messageArr.count>0) {
        if (messageArr.count==1) {
            newMessage=messageArr[0];
        }else{
            for (int i=0; i<messageArr.count; i++) {
                NSString *msg=[NSString stringWithFormat:@"%d . %@\n",i+1,messageArr[i]];
                newMessage=[newMessage stringByAppendingString:msg];
            }
        }
    }
    return newMessage;
}

#pragma mark -设置label边框
- (void)setLabelBorderColorWithLabel:(UILabel *)label color:(UIColor *)color{
    label.layer.borderColor=[color CGColor];
    label.layer.borderWidth=1.0;
}

#pragma mark -获取若干天后的日期
- (NSString *)getEndDateStrWithDays:(CGFloat)days beginStr:(NSString *)beginStr{
    NSDateFormatter *formatter=[NSDateFormatter new];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    NSDate *beginDate=[formatter dateFromString:beginStr];
    NSDate *theDate = [NSDate dateWithTimeInterval:60*60*24*days sinceDate:beginDate];
    NSString *endStr=[formatter stringFromDate:theDate];
    return endStr;
}

- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the se		lected object to the new view controller.
}
*/

@end
